<?php
/**
 * 教室信息类
 */
namespace app\admin\controller;

use think\App;
use think\facade\View;
use app\admin\model\Bannermodel;
use app\admin\model\Classifymodel;
use app\admin\validate\Content as validate;

class Banner extends Common
{
    protected $catmodel;

    public function __construct(App $app)
    {
        $this->validate = validate::class;
        $this->validateType = 'banner';
        $this->localModel = new Bannermodel();
        parent::__construct($app);
        $this->catmodel = new Classifymodel();
    }

    public function index()
    {
        $where = $showDataArr = [];

        $dataArr = $this->request->request('search/a', []);

        if($dataArr['name'])    $where[] = ['a.title', 'like', "%".$dataArr['name']."%"];
        if($dataArr['cid'])     $where[] = ['a.cid', '=', $dataArr['cid']];
        if($dataArr['status'])  $where[] = ['a.status', '=', $dataArr['status']];
        if(session('adminUserInfo.cid'))  $where[] = ['cid', 'in', session('adminUserInfo.cid').', 0'];

        $catWhere = [['fid', '=', 26], ['level', '=', 2], ['status', '=', 1]];
        $catList = $this->catmodel->findAllInfo('id, name', $catWhere);
        $list = $this->localModel->findAll($where, $this->request->param());//print_r($list);
        $showDataArr = ['infoData'=>$list['data'], 'pageData'=>$list['page'], 'catList'=>$catList, 'dataArr'=>$dataArr];
        View::assign($showDataArr);
        return view();
    }

    public function add(){
        $where = [['fid', '=', 26], ['level', '=', 2], ['status', '=', 1]];
        $showData['catList'] = $this->catmodel->findAllInfo('id, name', $where);
        $id = $this->request->request('id', '');

        if($id){
            $showData['id'] = $id;
            $showData['detail'] = $this->localModel->findDetaiInfoById('*', $id);
            View::assign($showData);
            return view('edit');
        }else{
            View::assign($showData);
            return view();
        }

    }

}
